﻿using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.Entities;
using SD.DAL;
using SD.IDAL;
using SD.IBUS;

namespace SD.BUS
{
    public class PremiseBIZ:BaseBIZ, IPremiseBIZ
    {
        #region IPremiseBIZ Members

        /// <summary>
        /// Get all premise stored in the database
        /// </summary>
        /// <returns>List of existing premise</returns>
        public List<Premise> GetAll(Boolean includeInactive)
        {
            List<Premise> lstResult = new List<Premise>();

            try
            {
                IPremiseDAO premiseDAO = new PremiseDAO();
                lstResult = premiseDAO.GetAll(includeInactive);
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return lstResult;
        }

        /// <summary>
        /// Get all premise of an organization
        /// </summary>
        /// <param name="orgId">ID of the organization</param>
        /// <returns>List of premises of an organization</returns>
        public List<Premise> GetByOrgId(string orgId, Boolean includeInactive)
        {
            List<Premise> result = new List<Premise>();

            try
            {
                IPremiseDAO premiseDAO = new PremiseDAO();
                result = premiseDAO.GetByOrgId(orgId, includeInactive);
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return result;
        }

        /// <summary>
        /// Get premise by its ID
        /// </summary>
        /// <param name="premiseId">The ID used to find the premise</param>
        /// <returns>Premise has the same ID with the inputed param</returns>
        public Premise GetById(string premiseId)
        {
            Premise result = null;

            try
            {
                IPremiseDAO premiseDAO = new PremiseDAO();
                result = premiseDAO.GetById(premiseId);
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return result;
        }

        /// <summary>
        /// Add new premise to database
        /// </summary>
        /// <param name="premise">The new premise will be added</param>
        public void Insert(Premise premise)
        {
            try
            {
                IPremiseDAO premiseDAO = new PremiseDAO();
                premiseDAO.Insert(premise);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Update an existing premise
        /// </summary>
        /// <param name="premise">The premise will be updated</param>
        public void Update(Premise premise)
        {
            try
            {
                IPremiseDAO premiseDAO = new PremiseDAO();
                premiseDAO.Update(premise);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Delete a premise
        /// </summary>
        /// <param name="premiseId"></param>
        public void Delete(string premiseId)
        {
            try
            {
                IPremiseDAO premiseDAO = new PremiseDAO();
                premiseDAO.Delete(premiseId);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
